var mongo = require("mongodb");
var host = "localhost";
var port = mongo.Connection.DEFAULT_PORT;
var server = new mongo.Server(host, port, {auto_reconnect: true});
var db = new mongo.Db('test', server, {safe: true});


db.open(function(err, db){
	if(err)
		throw err;
	else{
		console.log("connect success");

		db.collection('users', function(err, collection){
			if(err)
				throw err;
			else{
				collection.find({}).toArray(function(err, docs){
				// collection.find({username: 'kathy'}).toArray(function(err, docs){
				// collection.find({username: { $in: ['cgg', 'cgg2']}}).toArray(function(err, docs){
					console.log(docs);
					db.close();
				});
			}
		});
	}
});


db.on('close', function(err, db){
	if(err)
		throw err;
	else
		console.log("close success");
});
